﻿using BLL;
using MODEL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Loginter.系统维护
{
    public partial class AddUserInfo : System.Web.UI.Page
    {
        UserBLL ul = new UserBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                dr();
            }
        }
        public void dr()
        {
            juese_drop.DataSource = ul.juesedrop();
            juese_drop.DataTextField = "RoleName";
            juese_drop.DataValueField = "RoleID";
            juese_drop.DataBind();
            juese_drop.Items.Insert(0, new ListItem("--请选择--","0"));
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_Add_Click(object sender, EventArgs e)
        {
            UserBLL yb = new UserBLL();
            UserAdd ud = new UserAdd();
            ud.UserName = name_txt.Text;
            ud.Phone = phone_txt.Text;
            ud.Sex = radio_list.SelectedIndex;
            ud.Account = account_txt.Text;
            ud.FK_RoleID = Convert.ToInt32(juese_drop.SelectedValue);
            ud.Password = password_txt.Text;
            ud.Email = email_txt.Text;
            int result = yb.Add(ud);
            if (result > 0)
            {
                Response.Redirect("<script>alert('添加成功！');location.href='UserInfoWeiHu.aspx';</script>");
               // Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('添加成功！');location.href='UserInfoWeiHu.aspx';</script>");
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('添加失败！') </script>");
            }
        }

        /// <summary>
        /// 重置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_Result_Click(object sender, EventArgs e)
        {
            name_txt.Text = "";
            phone_txt.Text = null;
            account_txt.Text = null;
            juese_drop.SelectedValue =null;
            password_txt.Text = null;
            email_txt.Text = null;
        }
    }
}